package com.dtz.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dtz.rabbitmq.constant.RabbitConstant;


/**
 * 消息队列配置，路由模式
 * @author 陶志胜
 *
 */
@Configuration
public class DirectConfiguration {
	

	/**
	 * 定义交换机
	 * @return
	 */
	@Bean
	public DirectExchange directExchange() {
		return new DirectExchange(RabbitConstant.DIRECT_ORDER_EXCHANGE, true, false, null);
	}
	
	/**
	 * 定义消息队列
	 * @return
	 */
	@Bean
	public Queue directEmailQueue() {
		return new Queue(RabbitConstant.DIRECT_EMAIL_QUEUE, true);
	}
	
	@Bean
	public Queue directSmsQueue() {
		return new Queue(RabbitConstant.DIRECT_SMS_QUEUE, true);
	}
	
	@Bean
	public Queue directDuanxinQueue() {
		return new Queue(RabbitConstant.DIRECT_DUANXIN_QUEUE, true);
	}
	
	/**
	 * 将消息队列与交换机绑定
	 * @return
	 */
	@Bean
	public Binding directEmailBinding() {
		return BindingBuilder.bind(directEmailQueue()).to(directExchange()).with(RabbitConstant.EMAIL_ROUTING_KEY);
	}
	
	@Bean
	public Binding directSmsBinding() {
		return BindingBuilder.bind(directSmsQueue()).to(directExchange()).with(RabbitConstant.SMS_ROUTING_KEY);
	}
	
	@Bean
	public Binding directDuanxinBinding() {
		return BindingBuilder.bind(directDuanxinQueue()).to(directExchange()).with(RabbitConstant.DUANXIN_ROUTING_KEY);
	}
	
}
